import { observable, action } from 'mobx';
import { getRequest } from '../tools/requests';
import { Toast } from 'antd-mobile';

class Store {
  @observable goodsLists = [];
  @observable isLoading = true;
  @observable isNoMore = false;

  @action
  async getGoodsLists(pageIndex) {
    let result = await getRequest('goods_list/', {page: pageIndex, page_size: 20});
    this.setLoding(false);
    if (result.data) {
      this.setGoodsLists(result.data);
    }else {
      Toast.fail(result.msg, 1);
      this.setGoodsLists([]);
      this.setNoMore(true);
    }
  };

  @action
  async getGoodsListsPages(pageIndex) {
    return getRequest('goods_list/', {page: pageIndex, page_size: 20}); 
  }

  setGoodsLists(data) {
    this.goodsLists = data;
  };

  setLoding(status) {
    this.isLoading = status;
  };
  setNoMore(state) {
    this.isNoMore = state;
  }
}

export default new Store();